package org.spider.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Select;
import org.spider.model.entity.SpiderDictEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.spider.model.vo.SpiderDictVO;

import java.util.List;

/**
 * <p>
 * 字典表 Mapper 接口
 * </p>
 *
 * @author lzy
 * @since 2022-06-20 19:04:14
 */
@Mapper
public interface SpiderDictMapper extends BaseMapper<SpiderDictEntity> {


    /**
     * 自定义分页
     *
     * @param page
     * @param dict
     * @return
     */
    @Select("select * from spider_dict where dict_status = 0")
    List<SpiderDictVO> selectDictPage(IPage page, SpiderDictVO dict);

    /**
     * 获取字典表对应中文
     *
     * @param code    字典编号
     * @param dictKey 字典序号
     * @return
     */
    @Select("select dict_value from spider_dict where dict_code = #{code} and dict_key = #{dictKey} and dict_status = 2 limit 1")
    String getValue(String code, Integer dictKey);

    /**
     * 获取字典表
     *
     * @param code 字典编号
     * @return
     */
    @Select("select dict_code, dict_key, dict_value, dict_sort, dict_remark from spider_dict where dict_code = #{code} and dict_key >= 0 and dict_status = 2")
    List<SpiderDictEntity> getList(String code);

    /**
     * 获取树形节点
     *
     * @return
     */
    @Select("select id, dict_parent_id, dict_value as title, id as 'value', id as 'key' from spider_dict where dict_status = 2")
    List<SpiderDictVO> tree();
}
